package com.itheima.googleplay9.holder;

import android.support.v4.view.ViewCompat;
import android.text.format.Formatter;
import android.view.View;
import android.view.animation.OvershootInterpolator;
import android.widget.ImageView;
import android.widget.RatingBar;
import android.widget.TextView;

import com.itheima.googleplay9.R;
import com.itheima.googleplay9.api.Url;
import com.itheima.googleplay9.bean.AppInfo;
import com.itheima.googleplay9.global.GooglePlayApp;
import com.itheima.googleplay9.global.ImageLoaderOptions;
import com.nostra13.universalimageloader.core.ImageLoader;

import butterknife.Bind;

/**
 * Created by lxj on 2016/5/27.
 */
public class AppInfoHolder extends BaseHolder<AppInfo>{
    @Bind(R.id.iv_icon)
    ImageView ivIcon;
    @Bind(R.id.tv_name)
    TextView tvName;
    @Bind(R.id.rb_star)
    RatingBar rbStar;
    @Bind(R.id.tv_download_num)
    TextView tvDownloadNum;
    @Bind(R.id.tv_version)
    TextView tvVersion;
    @Bind(R.id.tv_date)
    TextView tvDate;
    @Bind(R.id.tv_size)
    TextView tvSize;
    @Override
    protected View initHolderView() {
        return View.inflate(GooglePlayApp.context, R.layout.layout_detail_app_info,null);
    }

    @Override
    public void bindData(AppInfo appInfo) {
        //执行旋转动画
        ViewCompat.animate(holderView).rotationXBy(360)
                .setInterpolator(new OvershootInterpolator())
                .setDuration(1000).start();

        tvName.setText(appInfo.getName());
        rbStar.setRating(appInfo.getStars());
        tvDownloadNum.setText("下载："+appInfo.getDownloadNum());
        tvVersion.setText("版本："+appInfo.getVersion());
        tvDate.setText("日期："+appInfo.getDate());
        tvSize.setText("大小："+ Formatter.formatFileSize(GooglePlayApp.context,appInfo.getSize()));
        //显示图片
        ImageLoader.getInstance().displayImage(Url.IMAGE_PREFIX+appInfo.getIconUrl()
            ,ivIcon, ImageLoaderOptions.round_options);
    }
}
